package com.work.formaldehyde.activityadapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.work.formaldehyde.R;
import com.work.formaldehyde.model.KePuListModel;
import com.work.formaldehyde.util.ApiUtils;

import java.util.ArrayList;

public class KePuListAdapter extends BaseAdapter {
    ArrayList<KePuListModel.data> list;
    Context context;

    public KePuListAdapter(ArrayList<KePuListModel.data> list, Context context) {
        // TODO Auto-generated constructor stub
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list != null ? list.get(position) : 0;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        convertView = LayoutInflater.from(context).inflate(R.layout.kepus_list_item, null);
        init i = new init();
        i.homeitem_text = convertView.findViewById(R.id.homeitem_text);
        i.homeitem_type = convertView.findViewById(R.id.homeitem_type);
        i.homeitem_img = convertView.findViewById(R.id.homeitem_img);
        i.homeitem_checknum = convertView.findViewById(R.id.homeitem_checknum);
        i.homeitem_text.setText(list.get(position).getTitle());
        i.homeitem_type.setText(list.get(position).getSource());
        i.homeitem_checknum.setText(list.get(position).getPv());
        ApiUtils.GET_IMAGE(context, list.get(position).getThumbnails(), i.homeitem_img);
        convertView.setTag(i);
        return convertView;
    }

    public static class init {
        //首页list的子控件
        TextView homeitem_text, homeitem_type, homeitem_checknum;
        ImageView homeitem_img;
    }
}

